package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldMaterialDetails;
import com.cleaningcloud.cld.domain.excelExport.ProjectRepositoryExprot;
import com.cleaningcloud.cld.service.ICldProjectRepositoryService;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.cld.domain.CldProjectRepository;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目仓库管理Controller
 *
 * @author cleaningcloud
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/projectRepository")
public class CldProjectRepositoryController  extends BaseController{

    @Autowired
    private ICldProjectRepositoryService projectRepositoryService;

    // TODO: 云管理调用
    /**
     * 查询仓库管理列表
     */
    @GetMapping("/listProjectRepository")
    public TableDataInfo listProjectRepository(CldProjectRepository cldProjectRepository)
    {
        startPage();
        List<CldProjectRepository> list = projectRepositoryService.selectCldProjectRepositoryList(cldProjectRepository);
        return getDataTable(list);
    }

    /**
     * 查询仓库管理列表
     */
    @GetMapping("/listMaterialDetails")
    public TableDataInfo listMaterialDetails(CldMaterialDetails cldMaterialDetails)
    {
        startPage();
        List<CldMaterialDetails> list = projectRepositoryService.selectCldMaterialDetailsList(cldMaterialDetails);
        return getDataTable(list);
    }

    /**
     * 根据岗位仓库id查询库存数量
     */
    @GetMapping("/selectGroupStockList/{wareId}")
    public AjaxResult selectGroupStockList(@PathVariable Long wareId)
    {
        CldMaterialDetails cldMaterialDetails = new CldMaterialDetails();
        cldMaterialDetails.setWareId(wareId);
        List<CldMaterialDetails> list = projectRepositoryService.selectCldMaterialDetailsList(cldMaterialDetails);
        return success(list);
    }

    /**
     * 查询仓库管理列表
     */
    @GetMapping("/selectGroupConsumeList/{wareId}")
    public AjaxResult selectGroupConsumeList(@PathVariable Long wareId)
    {
        List<CldMaterialDetails> list = projectRepositoryService.selectGroupConsumeList(wareId);
        return success(list);
    }


    /**
     * 查询仓库管理列表
     */
    @GetMapping("/listTeamMemberDetails")
    public AjaxResult listTeamMemberDetails(CldProjectRepository cldProjectRepository)
    {
        return success(projectRepositoryService.selectCldTeamMemberDetailsList(cldProjectRepository));
    }

    /**
     * 根据项目仓库id和商品id查询员工库存数量
     * @param cldMaterialDetails
     * @return
     */
    @GetMapping("/selectStaffStockList")
    public AjaxResult selectStaffStockList(CldMaterialDetails cldMaterialDetails){
        return success(projectRepositoryService.selectStaffStockList(cldMaterialDetails));
    }

    /**
     * @Author Shaw
     * @Description 项目仓库物资明细列表导出
     * @date: 2025-03-18 9:15
     * @param: //TODO
     */
    @Log(title = "项目仓库物资明细导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportProjectRepositoryList")
    public void exportProjectRepositoryList(HttpServletResponse response, ProjectRepositoryExprot projectRepositoryExprot){
        List<ProjectRepositoryExprot> list = projectRepositoryService.exportProjectRepositoryList(projectRepositoryExprot);
        ExcelUtil<ProjectRepositoryExprot> util = new ExcelUtil<ProjectRepositoryExprot>(ProjectRepositoryExprot.class);
        util.exportExcel(response, list, "项目仓库");
    }
}
